package com.example.petstoreservice.service;

import com.example.petstoreservice.entity.Product;
import com.example.petstoreservice.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    private ProductMapper productMapper;

    public List<Product> getAll() {
        return productMapper.getAll();
    }

    public boolean insertGood(Product product) {
        int affectRow = productMapper.insertGood(product);
        return affectRow > 0;
    }

    public boolean updateGood(Product product) {
        int affectRow = productMapper.updateGood(product);
        return affectRow > 0;
    }

    public boolean delete(Long id) {
        int affectRow = productMapper.delete(id);
        return affectRow > 0;
    }

    public Product incrementClickAndGet(Long id) {
        int affectRow = productMapper.incrementClick(id);
        if (affectRow > 0) {
            return productMapper.getById(id);
        }
        return null;
    }

    public List<Product> getAllSortedByClick() {
        return productMapper.getAllSortedByClick();
    }

    public List<Product> search(String keyword) {
        return productMapper.search(keyword);
    }

    public Product getById(Long id) {
        return productMapper.getById(id);
    }
    public List<Product> getByShopId(Long id){
        return productMapper.getByShopId(id);
    }
    public List<Product> getCat(){
        return productMapper.getCat();
    }
    public List<Product> getDog(){
        return productMapper.getDog();
    }
    public List<Product> findTop3Good(Long id){
        return productMapper.findTop3Good(id);
    }
    public Product getByIdWithout(Long id){
        return productMapper.getByIdWithout(id);
    }
}
